/**
 * 版权所有 2009-2015 中国中医科学院中医药信息研究所 何前锋 frontpeak@yahoo.com.cn
 **/
package cn.ac.cintcm.sh.domain;

import java.util.HashMap;
import java.util.List;

import org.jfree.data.category.DefaultCategoryDataset;


public class Prescriptions extends Elements {
	/**
	 *@str:有逗号或者空格分隔的一个或者多个中药字符串
	 *查找包含字符串中中药的方剂
	 */
	public Prescriptions searchHerbs(String str, boolean alias, boolean isVague) {
		return null;
	}
    
   public DefaultCategoryDataset compare(List<Prescription> pres) {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        if (pres != null) {
            for (Prescription p : pres) {
                HashMap<String, Item> qis  = p.getQiSummary();
                printQiSummary(qis, dataset, p, Qi9.ROOT);
            }
        }

        return dataset;
    }
    
    private void printQiSummary(HashMap<String, Item> qiItems,
            DefaultCategoryDataset dataset, Prescription p, String qi) {
        List<String> qis = Qi9.getNonLeafChildren(qi);
        if (qis.size() > 0) {
            for (String q : qis) {
                Item it = qiItems.get(q);
                double value = 0;
                if (it != null) {
                    value = it.getValue();
                }
                dataset.addValue(value, p.getName(), q);
            }
            for (String q : qis) {
                printQiSummary(qiItems,dataset, p, q);
            }
        }
    }

}